/**
 * Created by Alex on 16/12/31.
 */
'use strict'

const mongoose = require('mongoose')
const Interesting = mongoose.model('Interesting')
const Restaurant = mongoose.model('Restaurant')
const {imgUrl,hotUrl, interestingUrl, imgProcessType} = require('../../config')

exports.list = function* (next) {
  let {type = '1'} = this.query
  if(type === '1') {
    let {regions = interestingUrl[0].regionId} = this.query
    if(regions === '') regions = interestingUrl[0].regionId
    let list = yield Interesting
      .find(
        {
          regions: [regions]
        }, {
          title: 1,
          mainPic: 1,
          _id: 1,
          gathered: 1,
          url: 1
        })

    this.body = {
      msg: 'success',
      data: {
        select: interestingUrl,
        list,
        total: list.length
      },
      code: 200
    }
  } else if(type ==='2') {
    let {regions = hotUrl[0].regions} = this.query
    if(regions === '') regions = interestingUrl[0].regionId
    let list = yield Restaurant
      .find({regions: [regions]}, {
        name: 1,
        nameCn: 1,
        mainPic: 1,
        _id: 1,
        gathered: 1,
        url: 1
      })
    this.body = {
      msg: 'success',
      data: {
        list,
        select: hotUrl,
      },
      code: 200
    }
  } else {
    this.body = {
      msg: 'type is not exist',
      data: [],
      code: 201
    }
  }

}
